using System;
using System.Web;
using System.Web.UI;
using ASPNETVN.PORTAL.Components.Security;
using System.Collections;

namespace ASPNETVN.PORTAL.Components.UI
{
    public class AddEditModulePage : ModulePage
    {
        protected override void OnInit(EventArgs e)
        {
            if ((PortalSecurity.HasAddAuthorization(this.ModuleID) == false) && (PortalSecurity.HasEditAuthorization(this.ModuleID) == false))
            {
                PortalSecurity.AccessEditDenied();
            }
            base.OnInit(e);
        }
    }

    public class ModulePage : UserControl
    {
        private PortalModuleControl m_Container;
        public PortalModuleControl ParentControl
        {
            get
            {
                if (m_Container != null)
                    return m_Container;

                Control ctl = Parent;
                while (ctl.GetType() != typeof (PortalModuleControl))
                    ctl = ctl.Parent;

                m_Container = (PortalModuleControl) ctl;
                return m_Container;
            }
            set { m_Container = value; }
        }

        public bool IsViewable
        {
            get { return ParentControl.IsViewable; }
        }

        public bool IsAddable
        {
            get { return ParentControl.IsAddable; }
        }

        public bool IsEditable
        {
            get { return ParentControl.IsEditable; }
        }

        public bool IsDeleteable
        {
            get { return ParentControl.IsDeleteable; }
        }

        public bool IsManagerable
        {
            get { return ParentControl.IsManagerable; }
        }

        public Guid ModuleID
        {
            get { return ParentControl.ModuleID; }
        }

        public Guid TabID
        {
            get { return ParentControl.TabID; }
        }

        private int _ItemID;
        public int ItemID
        {
            get
            {
                if (_ItemID == 0)
                {
                    if (HttpContext.Current != null && Request.Params["ItemID"] != null)
                        _ItemID = Int32.Parse(Request.Params["ItemID"]);
                }
                return _ItemID;
            }
            set { _ItemID = value; }
        }

        public Hashtable Settings
        {
            get { return ParentControl.Settings; }
        }

        public void ShowMessage(string caption, string message)
        {
            ((ASPNETVN.PORTAL.Components.UI.Page)this.Page).ShowMessage(caption, message);
        }

        public void ShowMessage(string caption, string message, int width, int height)
        {
            ((ASPNETVN.PORTAL.Components.UI.Page)this.Page).ShowMessage(caption, message, width, height);
        }

        public void SetTitleText(string text)
        {
            ((ASPNETVN.PORTAL.Components.UI.Page)this.Page).SetTitleText(text);
        }

    }
}